﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Engine;

namespace Engine
{
   public class Camara
    {
        public Vector3 Position, Direction, Up, Left;
        public Matrix proyeccion, Vista;
        public bool tipoDeCamara; //si es 1ra o 3ra
        public float fieldOfView, aspectRatio, near;
        Actor3D AcotrToFollow;

        public Camara()
        {
            Position = Vector3.Zero;
            Direction = Vector3.UnitZ;
            Left = -Vector3.UnitX;
            Up = Vector3.UnitY;
            fieldOfView = 10000.0f;
            aspectRatio = 640.0f / 480.0f;
            near = 1.0f;
        }

        public Camara(Vector3 _Position, Vector3 _Direction, Vector3 _UP, Vector3 _Left, float _fieldOfView, float _aspectRatio, float _near)
        {
            Position = _Position;
            Direction = _Direction;
            Up = _UP;
            Left = _Left;
            fieldOfView = _fieldOfView;
            aspectRatio = _aspectRatio;
            near = _near;
        }

        public void rotate(Vector3 rotation)
        {
            Direction = Vector3.Transform(Direction, Matrix.CreateFromYawPitchRoll(rotation.X, rotation.Y, rotation.Z));
            Left = Vector3.Transform(Left, Matrix.CreateFromYawPitchRoll(rotation.X, rotation.Y, rotation.Z));
            Up = Vector3.Transform(Up, Matrix.CreateFromYawPitchRoll(rotation.X, rotation.Y, rotation.Z));

        }

        public void Update(int dTime)
        {
            Vector3 expectedPosition = -3 * AcotrToFollow.Direction + new Vector3(1, 1, 1);

            Vector3 direction = expectedPosition - Position;
            direction.Normalize();
            Position += direction * dTime;
        }
    }
}
